package cn.ibizlab.odoo.core.odoo_calendar.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Icalendar_alarm_manager;
import cn.ibizlab.odoo.core.odoo_calendar.domain.Calendar_alarm_manager;
import cn.ibizlab.odoo.core.odoo_calendar.filter.Calendar_alarm_managerSearchContext;
import cn.ibizlab.odoo.core.odoo_calendar.service.ICalendar_alarm_managerService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[活动提醒管理] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Calendar_alarm_managerServiceImpl implements ICalendar_alarm_managerService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Icalendar_alarm_managerClientService calendar_alarm_managerClientService;

    @Override
    public Calendar_alarm_manager get(Integer id) {
        Icalendar_alarm_manager clientModel = calendar_alarm_managerClientService.createModel();
        clientModel.setId(id);
        calendar_alarm_managerClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Calendar_alarm_manager get(Calendar_alarm_manager calendar_alarm_manager) {
        Calendar_alarm_manager retcalendar_alarm_manager = this.get(calendar_alarm_manager.getId()) ;
    	BeanCopier copier=BeanCopier.create(retcalendar_alarm_manager.getClass(), calendar_alarm_manager.getClass(), false);
        copier.copy(retcalendar_alarm_manager, calendar_alarm_manager, null);
        return calendar_alarm_manager ;
    }

    @Override
    public void updateBatch(List<Calendar_alarm_manager> calendar_alarm_managers, int batchSize) {

        //calendar_alarm_managerClientService.updateBatch(calendar_alarm_managers,batchSize) ;

    }

    @Override
    public boolean update(Calendar_alarm_manager calendar_alarm_manager) {
        boolean bOk = false ;
        Icalendar_alarm_manager clientModel = this.convert2Model(calendar_alarm_manager,null);
        calendar_alarm_managerClientService.update(clientModel) ;
        this.convert2Domain(clientModel,calendar_alarm_manager) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Calendar_alarm_manager> calendar_alarm_managers, int batchSize) {

                        //calendar_alarm_managerClientService.createBatch(calendar_alarm_managers,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //calendar_alarm_managerClientService.removeBatch(calendar_alarm_managers) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Icalendar_alarm_manager clientModel = calendar_alarm_managerClientService.createModel();
        clientModel.setId(id);
        calendar_alarm_managerClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Calendar_alarm_manager calendar_alarm_manager) {
        boolean bOk = false ;
        Icalendar_alarm_manager clientModel = this.convert2Model(calendar_alarm_manager,null);
        calendar_alarm_managerClientService.create(clientModel) ;
        this.convert2Domain(clientModel,calendar_alarm_manager);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Calendar_alarm_manager> searchDefault(Calendar_alarm_managerSearchContext context) {
        List<Calendar_alarm_manager> list = new ArrayList<Calendar_alarm_manager>();
        Page<cn.ibizlab.odoo.core.client.model.Icalendar_alarm_manager> clientModelList = calendar_alarm_managerClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Icalendar_alarm_manager clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Calendar_alarm_manager>(list, context.getPageable(), clientModelList.getTotalElements());
    }




    public Icalendar_alarm_manager convert2Model(Calendar_alarm_manager domain , Icalendar_alarm_manager model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = calendar_alarm_managerClientService.createModel() ;
        }

         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
        return model ;
    }

    public Calendar_alarm_manager convert2Domain( Icalendar_alarm_manager model ,Calendar_alarm_manager domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Calendar_alarm_manager();
        }

        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        return domain ;
    }


}
